<template>
  <div class="index_header">
    <div class="index_header_header">
      <div class="index_header_left">
        <el-icon @click="handleImg" class="open_img">
          <Menu/>
        </el-icon>
      </div>
      <div class="index_header_right">
        <el-dropdown @command="handleCommand">
        <span class="el-dropdown-link">
          {{ userInfo.userName }}
          <el-icon class="el-icon--right">
            <arrow-down/>
          </el-icon>
        </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item :command="1">退出系统</el-dropdown-item>
              <el-dropdown-item :command="2">修改密码</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
    <div class="index_header_bottom">
      <el-tabs class="el_tabs" type="card" closable>
        <el-tab-pane
            :key="index"
            v-for="(item, index) in editableTabs"
            :label="item.title"
            :name="item.name"
        >
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script setup lang="ts">
import userStore from "@/store/modules/user";
import {ref, defineEmits} from "vue";

const emits = defineEmits(['changeCollapse'])
const userPinia = userStore()
const userInfo = userPinia.getUserInfo
let isCollapse = ref(false)
const handleImg = () => {
  isCollapse.value = !isCollapse.value
  emits('changeCollapse', isCollapse.value)
}


const handleCommand = (val: number) => {
  console.log(val)
  if (val === 1) {
    userPinia.handleOut()
  }
}
const editableTabs = ref([
  {
    title: 'Tab 1',
    name: '1',
    content: 'Tab 1 content',
  },
  {
    title: 'Tab 2',
    name: '2',
    content: 'Tab 2 content',
  },
])
</script>

<style lang="less" scoped>
.index_header {
  width: 100%;
  height: 80px;
  //border-bottom: 1px solid #999999;

  .index_header_header {
    display: flex;
    align-items: center;
    height: 48px;
    border-bottom: 1px solid #e4e7ed;

    .index_header_left {
      flex: 1;

      .open_img {
        margin-left: 20px;
        cursor: pointer;
      }
    }

    .index_header_right {
      padding-right: 20px;

      .el-dropdown-link {
        cursor: pointer;
        color: var(--el-color-primary);
        display: flex;
        align-items: center;
      }

      .el-dropdown-link:focus {
        outline: none;
      }
    }
  }

  .index_header_bottom {
    display: flex;
    align-items: center;
    height: 30px;
    margin-top: 2px;

    /deep/ .el_tabs {
      width: 100%;
      height: 30px;

      .el-tabs__item {
        height: 30px;
      }

      .el-tabs__header {
        height: 30px;
      }
    }
  }
}
</style>
